﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //实例
     male=QString::fromLocal8Bit("男");
     female=QString::fromLocal8Bit("女");
    //
    radioM=new QRadioButton(this);
    radioW=new QRadioButton(this);
    label=new QLabel(this);
    //位置
    radioM->setGeometry(QRect(50,50,50,50));
    radioW->setGeometry(QRect(100,50,50,50));
    label->setGeometry(QRect(50,100,100,25));

    radioM->setText(male);
    radioW->setText(female);
    //默认选择
    radioM->setChecked(true);
    label->setText(female);
    //事件
    connect(
            radioM,
            SIGNAL(clicked(bool)),
            this,
            SLOT(radioChange())
            );
    connect(
                radioW,
                SIGNAL(clicked(bool)),
                this,
                SLOT(radioChange())
            );


}
//Radio 点击方法
void MainWindow::radioChange()
{
   if(sender()==radioM)
   {
    label->setText(male);
   }else if(sender()==radioW)
   {
       label->setText(female);
   }
}
MainWindow::~MainWindow()
{
    delete ui;
}
